using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class MainPage : MonoBehaviour
{
    public Button mailBtn;
    public Button shopBtn;

    public GameObject mailPage;
    public GameObject shopPage;

    public TextMeshProUGUI mailRedPoint;
    public TextMeshProUGUI shopRedPoint;
    // Start is called before the first frame update
    void Start()
    {
        //红点初始化，必须首先执行
        RedPointMgr.Instance.Init();
        
        mailBtn.onClick.AddListener(OnMailBtnClick);
        shopBtn.onClick.AddListener(OnShopBtnClick);

        mailRedPoint.transform.parent.gameObject.SetActive(false);
        shopRedPoint.transform.parent.gameObject.SetActive(false);
        
        //数据获取，放在红点注册 之前也行
        // MailMgr.Instance.Init();
        // ShopMgr.Instance.Init();
        
        //红点注册
        RedPointMgr.Instance.GetNode(ERedPoint.Mail).AddOnRedPointStateChangeListener((node) =>
        {
            mailRedPoint.transform.parent.gameObject.SetActive(node.RedCount>0);
            mailRedPoint.text = node.RedCount.ToString();
        });
        
        RedPointMgr.Instance.GetNode(ERedPoint.Shop).AddOnRedPointStateChangeListener ((node) =>
        {
            shopRedPoint.transform.parent.gameObject.SetActive(node.RedCount>0);
            shopRedPoint.text = node.RedCount.ToString();
        });
        //数据获取，放在红点注册 之前也行
        MailMgr.Instance.Init();
        ShopMgr.Instance.Init();
    }

    private void OnShopBtnClick()
    {
        shopPage.SetActive(true);
        gameObject.SetActive(false);
    }

    private void OnMailBtnClick()
    {
        mailPage.SetActive(true);
        gameObject.SetActive(false);
    }
}
